﻿Imports Aricie.DNN.Modules.LuceneSearch.ModuleProviders
Imports Aricie.DNN.Modules.LuceneSearch.Business
Imports System.Linq
Imports System.Data
Imports Aricie.Services

Namespace Aricie.DNN.Modules.LuceneSearch.ModuleProviders

    Public Class AjaxFAQProvider
        Implements ILuceneSearchableUpgrade

        Public Sub UpgradeSearchItem(ByVal portalId As Integer, ByRef searchItem As Aricie.DNN.Modules.LuceneSearch.Business.LuceneSearchItemInfo) Implements Aricie.DNN.Modules.LuceneSearch.ModuleProviders.ILuceneSearchableUpgrade.UpgradeSearchItem

            Dim t As Type = ReflectionHelper.CreateType("DNNCentric.AJAXFAQ.Components.FAQController, DNNCentric.AJAXFAQ")
            Dim provider = ReflectionHelper.CreateObject(t)


            Dim QuestionId As Integer = -1
            If (Integer.TryParse(searchItem.SearchKey, QuestionId)) Then
                Dim Categories As DataTable = DirectCast(t.InvokeMember("GetCatQuestionIDforSearch", Reflection.BindingFlags.InvokeMethod, Nothing, provider, New Object() {QuestionId}), DataTable)
                For Each c As DataRow In Categories.Rows
                    Dim CategoryId = Integer.Parse(c(0))
                    Dim CatDataTable As DataTable = DirectCast(t.InvokeMember("GetCategoryNameByID", Reflection.BindingFlags.InvokeMethod, Nothing, provider, New Object() {CategoryId}), DataTable)
                    searchItem.ContentTaxonomy.Add(CatDataTable.Rows(0)(0).ToString().Trim())
                Next

                searchItem.Title = searchItem.Description
            End If

            searchItem.ItemType = "Question"
        End Sub

    End Class

End Namespace